#include <gtest\gtest.h>
#include <Zaf\String\Split.h>



TEST(Split, CharSplitter) {

	//char
	std::vector<std::string> strContainer;

	Zaf::String::CharSplitterScanner<char> charSplitter(' ');

	std::string str("");
	Zaf::String::Split(str, std::back_inserter(strContainer), charSplitter);
	ASSERT_EQ(1, strContainer.size());
	ASSERT_EQ("", strContainer[0]);

	strContainer.clear();
	str = "123";
	Zaf::String::Split(str, std::back_inserter(strContainer), charSplitter);
	ASSERT_EQ(1, strContainer.size());
	ASSERT_EQ("123", strContainer[0]);

	strContainer.clear();
	str = "   ";
	Zaf::String::Split(str, std::back_inserter(strContainer), charSplitter);
	ASSERT_EQ(4, strContainer.size());
	ASSERT_EQ("", strContainer[0]);
	ASSERT_EQ("", strContainer[1]);
	ASSERT_EQ("", strContainer[2]);
	ASSERT_EQ("", strContainer[3]);

	strContainer.clear();
	str = "1 2 3";
	Zaf::String::Split(str, std::back_inserter(strContainer), charSplitter);
	ASSERT_EQ(3, strContainer.size());
	ASSERT_EQ("1", strContainer[0]);
	ASSERT_EQ("2", strContainer[1]);
	ASSERT_EQ("3", strContainer[2]);

	strContainer.clear();
	str = " 123 456 789 ";
	Zaf::String::Split(str, std::back_inserter(strContainer), charSplitter);
	ASSERT_EQ(5, strContainer.size());
	ASSERT_EQ("", strContainer[0]);
	ASSERT_EQ("123", strContainer[1]);
	ASSERT_EQ("456", strContainer[2]);
	ASSERT_EQ("789", strContainer[3]);
	ASSERT_EQ("", strContainer[4]);

	//wchar_t
	std::vector<std::wstring> wstrContainer;

	Zaf::String::CharSplitterScanner<wchar_t> wcharSplitter(L' ');

	std::wstring wstr(L"");
	Zaf::String::Split(wstr, std::back_inserter(wstrContainer), wcharSplitter);
	ASSERT_EQ(1, wstrContainer.size());
	ASSERT_EQ(L"", wstrContainer[0]);

	wstrContainer.clear();
	wstr = L"123";
	Zaf::String::Split(wstr, std::back_inserter(wstrContainer), wcharSplitter);
	ASSERT_EQ(1, wstrContainer.size());
	ASSERT_EQ(L"123", wstrContainer[0]);

	wstrContainer.clear();
	wstr = L"   ";
	Zaf::String::Split(wstr, std::back_inserter(wstrContainer), wcharSplitter);
	ASSERT_EQ(4, wstrContainer.size());
	ASSERT_EQ(L"", wstrContainer[0]);
	ASSERT_EQ(L"", wstrContainer[1]);
	ASSERT_EQ(L"", wstrContainer[2]);
	ASSERT_EQ(L"", wstrContainer[3]);

	wstrContainer.clear();
	wstr = L"1 2 3";
	Zaf::String::Split(wstr, std::back_inserter(wstrContainer), wcharSplitter);
	ASSERT_EQ(3, wstrContainer.size());
	ASSERT_EQ(L"1", wstrContainer[0]);
	ASSERT_EQ(L"2", wstrContainer[1]);
	ASSERT_EQ(L"3", wstrContainer[2]);

	wstrContainer.clear();
	wstr = L" 123 456 789 ";
	Zaf::String::Split(wstr, std::back_inserter(wstrContainer), wcharSplitter);
	ASSERT_EQ(5, wstrContainer.size());
	ASSERT_EQ(L"", wstrContainer[0]);
	ASSERT_EQ(L"123", wstrContainer[1]);
	ASSERT_EQ(L"456", wstrContainer[2]);
	ASSERT_EQ(L"789", wstrContainer[3]);
	ASSERT_EQ(L"", wstrContainer[4]);
}



TEST(Split, StringSplitter) {

	//char
	std::vector<std::string> strCon;

	Zaf::String::StringSplitterScanner<char> strSplitter("||");

	std::string str("");
	Zaf::String::Split(str, std::back_inserter(strCon), strSplitter);
	ASSERT_EQ(1, strCon.size());

	strCon.clear();
	str = "|||||||";
	Zaf::String::Split(str, std::back_inserter(strCon), strSplitter);
	ASSERT_EQ(4, strCon.size());
	ASSERT_EQ("", strCon[0]);
	ASSERT_EQ("", strCon[1]);
	ASSERT_EQ("", strCon[2]);
	ASSERT_EQ("|", strCon[3]);

	strCon.clear();
	str = "abc||e||dfgds";
	Zaf::String::Split(str, std::back_inserter(strCon), strSplitter);
	ASSERT_EQ(3, strCon.size());
	ASSERT_EQ("abc", strCon[0]);
	ASSERT_EQ("e", strCon[1]);
	ASSERT_EQ("dfgds", strCon[2]);

	strCon.clear();
	str = "||abc||ab||c||";
	Zaf::String::Split(str, std::back_inserter(strCon), strSplitter);
	ASSERT_EQ(5, strCon.size());
	ASSERT_EQ("", strCon[0]);
	ASSERT_EQ("abc", strCon[1]);
	ASSERT_EQ("ab", strCon[2]);
	ASSERT_EQ("c", strCon[3]);
	ASSERT_EQ("", strCon[4]);

	strCon.clear();
	str = "123";
	Zaf::String::Split(str, std::back_inserter(strCon), Zaf::String::StringSplitterScanner<char>(""));
	ASSERT_EQ(1, strCon.size());
	ASSERT_EQ("123", strCon[0]);

	//wchar_t
	std::vector<std::wstring> wstrCon;

	Zaf::String::StringSplitterScanner<wchar_t> wstrSplitter(L"||");

	std::wstring wstr(L"");
	Zaf::String::Split(wstr, std::back_inserter(wstrCon), wstrSplitter);
	ASSERT_EQ(1, wstrCon.size());

	wstrCon.clear();
	wstr = L"|||||||";
	Zaf::String::Split(wstr, std::back_inserter(wstrCon), wstrSplitter);
	ASSERT_EQ(4, wstrCon.size());
	ASSERT_EQ(L"", wstrCon[0]);
	ASSERT_EQ(L"", wstrCon[1]);
	ASSERT_EQ(L"", wstrCon[2]);
	ASSERT_EQ(L"|", wstrCon[3]);

	wstrCon.clear();
	wstr = L"abc||e||dfgds";
	Zaf::String::Split(wstr, std::back_inserter(wstrCon), wstrSplitter);
	ASSERT_EQ(3, wstrCon.size());
	ASSERT_EQ(L"abc", wstrCon[0]);
	ASSERT_EQ(L"e", wstrCon[1]);
	ASSERT_EQ(L"dfgds", wstrCon[2]);

	wstrCon.clear();
	wstr = L"||abc||ab||c||";
	Zaf::String::Split(wstr, std::back_inserter(wstrCon), wstrSplitter);
	ASSERT_EQ(5, wstrCon.size());
	ASSERT_EQ(L"", wstrCon[0]);
	ASSERT_EQ(L"abc", wstrCon[1]);
	ASSERT_EQ(L"ab", wstrCon[2]);
	ASSERT_EQ(L"c", wstrCon[3]);
	ASSERT_EQ(L"", wstrCon[4]);

	wstrCon.clear();
	wstr = L"123";
	Zaf::String::Split(wstr, std::back_inserter(wstrCon), Zaf::String::StringSplitterScanner<wchar_t>(L""));
	ASSERT_EQ(1, wstrCon.size());
	ASSERT_EQ(L"123", wstrCon[0]);
}



TEST(Split, CharArraySplitter) {

	//char
	std::vector<std::string> strCon;

	Zaf::String::CharArraySplitterScanner<char> charArraySplitter("(){}");

	std::string str("");
	Zaf::String::Split(str, std::back_inserter(strCon), charArraySplitter);
	ASSERT_EQ(1, strCon.size());
	ASSERT_EQ("", strCon[0]);

	strCon.clear();
	str = "abcdef";
	Zaf::String::Split(str, std::back_inserter(strCon), charArraySplitter);
	ASSERT_EQ(1, strCon.size());
	ASSERT_EQ("abcdef", strCon[0]);

	strCon.clear();
	str = "ab)d{cf}12(132";
	Zaf::String::Split(str, std::back_inserter(strCon), charArraySplitter);
	ASSERT_EQ(5, strCon.size());
	ASSERT_EQ("ab", strCon[0]);
	ASSERT_EQ("d", strCon[1]);
	ASSERT_EQ("cf", strCon[2]);
	ASSERT_EQ("12", strCon[3]);
	ASSERT_EQ("132", strCon[4]);

	strCon.clear();
	str = "(13{23432}11)";
	Zaf::String::Split(str, std::back_inserter(strCon), charArraySplitter);
	ASSERT_EQ(5, strCon.size());
	ASSERT_EQ("", strCon[0]);
	ASSERT_EQ("13", strCon[1]);
	ASSERT_EQ("23432", strCon[2]);
	ASSERT_EQ("11", strCon[3]);
	ASSERT_EQ("", strCon[4]);

	strCon.clear();
	str = "123";
	Zaf::String::Split(str, std::back_inserter(strCon), Zaf::String::CharArraySplitterScanner<char>(""));
	ASSERT_EQ(1, strCon.size());
	ASSERT_EQ("123", strCon[0]);

	//wchar_t
	std::vector<std::wstring> wstrCon;

	Zaf::String::CharArraySplitterScanner<wchar_t> wcharArraySplitter(L"(){}");

	std::wstring wstr(L"");
	Zaf::String::Split(wstr, std::back_inserter(wstrCon), wcharArraySplitter);
	ASSERT_EQ(1, wstrCon.size());
	ASSERT_EQ(L"", wstrCon[0]);

	wstrCon.clear();
	wstr = L"abcdef";
	Zaf::String::Split(wstr, std::back_inserter(wstrCon), wcharArraySplitter);
	ASSERT_EQ(1, wstrCon.size());
	ASSERT_EQ(L"abcdef", wstrCon[0]);

	wstrCon.clear();
	wstr = L"ab)d{cf}12(132";
	Zaf::String::Split(wstr, std::back_inserter(wstrCon), wcharArraySplitter);
	ASSERT_EQ(5, wstrCon.size());
	ASSERT_EQ(L"ab", wstrCon[0]);
	ASSERT_EQ(L"d", wstrCon[1]);
	ASSERT_EQ(L"cf", wstrCon[2]);
	ASSERT_EQ(L"12", wstrCon[3]);
	ASSERT_EQ(L"132", wstrCon[4]);

	wstrCon.clear();
	wstr = L"(13{23432}11)";
	Zaf::String::Split(wstr, std::back_inserter(wstrCon), wcharArraySplitter);
	ASSERT_EQ(5, wstrCon.size());
	ASSERT_EQ(L"", wstrCon[0]);
	ASSERT_EQ(L"13", wstrCon[1]);
	ASSERT_EQ(L"23432", wstrCon[2]);
	ASSERT_EQ(L"11", wstrCon[3]);
	ASSERT_EQ(L"", wstrCon[4]);

	wstrCon.clear();
	wstr = L"123";
	Zaf::String::Split(wstr, std::back_inserter(wstrCon), Zaf::String::CharArraySplitterScanner<wchar_t>(L""));
	ASSERT_EQ(1, wstrCon.size());
	ASSERT_EQ(L"123", wstrCon[0]);
}



